package com.example.aggregatedemo.arrary;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

@SpringBootTest
public class SetTest_1 {
    @Test
    void DemoTest1(){
        //1.创建
        Set<String> set=new HashSet<>();
        //2 添加
        boolean r1=set.add("aaa");
        boolean r2=set.add("aaa");
        set.add("bbb");
        set.add("ccc");
        System.out.println(r1);
        System.out.println(r2);
        System.out.println(set);

        //迭代器遍历
        Iterator<String> it = set.iterator();
        while (it.hasNext()){
            String str=it.next();
            System.out.println(str);
        }
        System.out.println("______增强for______");

        //增强for
        for (String s : set) {
            System.out.println(s);
        }

        System.out.println("______Lambda______");
        //Lambda
        set.forEach(s->System.out.println(s));



    }
}
